Telegram Group & Telegram Channel
It's time for us to talk about async/await in Python. That's a big and difficult topic but a very important one if you're working with the network.

Everything your program does belongs to one of the two classes:

+ CPU-bound tasks. This is when you do a lot of computations, and the fan of your PC makes helicopter noises. You can speed up computations with multiprocessing, which is a pain in the ass to do correctly.

+ IO-bound tasks. This is when your code does nothing except wait for a response from the outside world. It includes making all kinds of network requests (sending logs, querying a database, crawling a website), network responses (like when you have a web app), and working with files. You can speed up it using async/await syntax.

The basics are quite simple:

1. If you define a function using async def instead of just def, it will return a "coroutine" when is called instead of immediately running and calculating the result.

2. If you call inside an async function another async function with adding await before it, Python will request execution of this coroutine, switch to something else, and return the result when it is available.

3. The module asyncio contains some functions to work with async code and the scheduler that decides when to run which task.

This is a very basic overview. You can read the official asyncio documentation to learn more. In follow-up posts, we will cover most of asyncio functions, one by one.



tg-me.com/pythonetc/720
Create:
Last Update:

It's time for us to talk about async/await in Python. That's a big and difficult topic but a very important one if you're working with the network.

Everything your program does belongs to one of the two classes:

+ CPU-bound tasks. This is when you do a lot of computations, and the fan of your PC makes helicopter noises. You can speed up computations with multiprocessing, which is a pain in the ass to do correctly.

+ IO-bound tasks. This is when your code does nothing except wait for a response from the outside world. It includes making all kinds of network requests (sending logs, querying a database, crawling a website), network responses (like when you have a web app), and working with files. You can speed up it using async/await syntax.

The basics are quite simple:

1. If you define a function using async def instead of just def, it will return a "coroutine" when is called instead of immediately running and calculating the result.

2. If you call inside an async function another async function with adding await before it, Python will request execution of this coroutine, switch to something else, and return the result when it is available.

3. The module asyncio contains some functions to work with async code and the scheduler that decides when to run which task.

This is a very basic overview. You can read the official asyncio documentation to learn more. In follow-up posts, we will cover most of asyncio functions, one by one.

BY Python etc


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 280

Share with your friend now:
tg-me.com/pythonetc/720

View MORE
Open in Telegram


Python etc Telegram | DID YOU KNOW?

Date: |

Telegram announces Search Filters

With the help of the Search Filters option, users can now filter search results by type. They can do that by using the new tabs: Media, Links, Files and others. Searches can be done based on the particular time period like by typing in the date or even “Yesterday”. If users type in the name of a person, group, channel or bot, an extra filter will be applied to the searches.

What Is Bitcoin?

Bitcoin is a decentralized digital currency that you can buy, sell and exchange directly, without an intermediary like a bank. Bitcoin’s creator, Satoshi Nakamoto, originally described the need for “an electronic payment system based on cryptographic proof instead of trust.” Each and every Bitcoin transaction that’s ever been made exists on a public ledger accessible to everyone, making transactions hard to reverse and difficult to fake. That’s by design: Core to their decentralized nature, Bitcoins aren’t backed by the government or any issuing institution, and there’s nothing to guarantee their value besides the proof baked in the heart of the system. “The reason why it’s worth money is simply because we, as people, decided it has value—same as gold,” says Anton Mozgovoy, co-founder & CEO of digital financial service company Holyheld.

Python etc from no


Telegram Python etc
FROM USA